package com.aoxin.controller.activity;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.activity.SlfSigninConfig;
import com.aoxin.service.inter.activity.SigninConfigService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.ThreadLocalUtil;

/**
 * 签到配置 Controller
 * 
 * @author Melody
 * @date 2018年4月28日 下午5:24:14
 */
@Controller
@ResponseBody
@RequestMapping("/web/signinConfig")
public class SigninConfigController {

	@Autowired
	private SigninConfigService signinConfigService;

	@RequestMapping("/insertSigninConfig")
	public AjaxRes insertSigninConfig(AjaxRes ajaxRes, SlfSigninConfig slfSigninConfig) {
		try {
			slfSigninConfig.setCreateDate(new Date());
			slfSigninConfig.setCreatorId(ThreadLocalUtil.getEmployee().getEmployeeId());
			this.signinConfigService.insertSigninConfig(slfSigninConfig);
			ajaxRes.setSucceedMsg(Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	@RequestMapping("/updateSigninConfig")
	public AjaxRes updateSigninConfig(AjaxRes ajaxRes, SlfSigninConfig slfSigninConfig) {
		try {
			this.signinConfigService.updateSigninConfig(slfSigninConfig);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	@RequestMapping("/deleteSigninConfigs")
	public AjaxRes deleteSigninConfigs(AjaxRes ajaxRes, @RequestParam("signinConfigIds") List<Integer> signinConfigIds) {
		try {
			this.signinConfigService.deleteSigninConfigs(signinConfigIds);
			ajaxRes.setSucceedMsg(Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	@RequestMapping("/updateSigninConfigStates")
	public AjaxRes updateSigninConfigStates(AjaxRes ajaxRes, @RequestParam("state") Integer state, @RequestParam("signinConfigIds") List<Integer> signinConfigIds) {
		try {
			this.signinConfigService.updateSigninConfigStates(state, signinConfigIds);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	@RequestMapping("/getSigninConfigList")
	public AjaxRes getSigninConfigList(AjaxRes ajaxRes) {
		try {
			List<SlfSigninConfig> slfSigninConfigs=  this.signinConfigService.getSigninConfigList();
			ajaxRes.setSucceed(slfSigninConfigs,Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
